﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThucTapOnsoft.Models;

namespace ThucTapOnsoft.Content.Controllers
{
    
    public class monController : Controller
    {
       thuctapEntities1 bd= new thuctapEntities1();
        //
        // GET: /mon/
      
        public ActionResult creat()
        {
           
            return View();
        }
        [HttpPost]
        public ActionResult creat(FormCollection connection, MONHOC monhoc)
        {
            string mamon = connection["txtmamon"];
            string tenmon = connection["txttenmon"];
            int sotiet = int.Parse(connection["txtsotiet"]);
            int thutu = int.Parse(connection["txtthutu"]);

            monhoc.mamon = mamon;
            monhoc.tenmon = tenmon;
            monhoc.sotiet = sotiet;
            monhoc.thutu = thutu;
            bd.MONHOCs.Add(monhoc);
            bd.SaveChanges();
            return creat();
            
        }
        public ActionResult edit(int id )
        {
            var monhoc = bd.MONHOCs.First(m => m.Id == id);
            return View(monhoc);
        }
        [HttpPost]
        public ActionResult edit(int id, FormCollection connection)
        {
         var monhoc = bd.MONHOCs.First(m=>m.Id==id);
           string mamon = connection["txtmamon"];
            string tenmon = connection["txttenmon"];
            int sotiet = int.Parse(connection["txtsotiet"]);
            int thutu = int.Parse(connection["txtthutu"]);

            monhoc.Id = id;
            monhoc.mamon = mamon;
            monhoc.tenmon = tenmon;
            monhoc.sotiet = sotiet;
            monhoc.thutu = thutu;
            UpdateModel(monhoc);
            bd.SaveChanges();
            return Redirect("edit");
        }
        
        public ActionResult Index()
        {
            return View();
        }

    }
}
